package PTA.MainXDX.ex04;

import PTA.Mianxiangduixiang.ex42.P;

import java.util.Arrays;
import java.util.Scanner;
abstract class Shape{
    static double PI=3.14;
    public abstract double getPerimeter();
    public abstract double getArea();
}
class Rectangle extends Shape{
private int width;
private int length;

    public Rectangle() {
    }

    public Rectangle(int width, int length) {
        this.width = width;
        this.length = length;
    }

    @Override
    public double getPerimeter() {
        return (width+length)*2;
    }

    @Override
    public double getArea() {
        return width*length;
    }

    @Override
    public String toString() {
        return "Rectangle [" +
                "width=" + width +
                ", length=" + length +
                ']';
    }
}
class Circle extends Shape{
private int radius;

    public Circle() {
    }

    public Circle(int radius) {
        this.radius = radius;
    }

    @Override
    public double getPerimeter() {
        return PI*2*radius;
    }

    @Override
    public double getArea() {
        return PI*radius*radius;
    }

    @Override
    public String toString() {
        return "Circle [" +
                "radius=" + radius +
                ']';
    }
}

public class ex04 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Shape arr[] = new Shape[n];
sc.nextLine();
for(int i=0;i<n;i++){
    String line = sc.nextLine();
    if(line.equals("rect")){
        int width = sc.nextInt();
        int length = sc.nextInt();
        arr[i] = new Rectangle(width,length);
        sc.nextLine();
    }else if(line.equals("cir")){
        int radius = sc.nextInt();
        arr[i] = new Circle(radius);
        sc.nextLine();
    }
}
        System.out.println(sumAllPerimeter(arr));
        System.out.println(sumAllArea(arr));
        System.out.println(Arrays.toString(arr));
        for(Shape s:arr){
            System.out.println(s.getClass()+","+s.getClass().getSuperclass());
        }
    }
    public static double sumAllPerimeter(Shape arr[]){
        double ret = 0;
        for(Shape s:arr){
         ret +=s.getPerimeter();
        }
        return  ret;
    }
    public static double sumAllArea(Shape arr[]){
        double ret = 0;
        for(Shape s:arr){
            ret+=s.getArea();

        }
        return ret;
    }
}
